#pragma once
/* Copyright (C) 2009 Vlad Roubtsov. All rights reserved. */

#include <map>
using std::map;
#include <string>

#include "vr/deject/factory/conversion.hpp"
#include "vr/util/assertions.hpp"
#include "vr/util/utility.hpp"

//----------------------------------------------------------------------------
namespace vr
{
namespace deject
{
namespace factory
{
/**
 * This class mediates numeric values as passed from the Lua configuration into
 * C++ space (e.g. component value parameters).
 */
class value
{
    public: // ...............................................................

        typedef double numeric_type; // default Lua numeric type representation
        typedef map<std::string, value> map_of_val_type; // use maps to have determistic key ordering


        template<typename T>
        value (const T v) :
            m_value (conversion<T, numeric_type>::convert (v))
        {
        }

        // note: avoid general templatized conversion operators
        // (these tend to cause resolution ambiguities)

#define __VR_DEFINE_CONVERSION(T) \
        \
        operator T () const\
        {\
            return conversion<numeric_type, T >::convert (m_value);\
        }

        __VR_DEFINE_CONVERSION (long double)
        __VR_DEFINE_CONVERSION (double)
        __VR_DEFINE_CONVERSION (int64_t)
        __VR_DEFINE_CONVERSION (int32_t)
        __VR_DEFINE_CONVERSION (int16_t)
        __VR_DEFINE_CONVERSION (int8_t)
        __VR_DEFINE_CONVERSION (bool)

#undef __VR_DEFINE_CONVERSION

    protected: // ............................................................

    private: // ..............................................................

        numeric_type m_value;

}; // end of class

} // end of 'value'
} // end of 'deject'
} // end of namespace
//----------------------------------------------------------------------------
